import java.util.Arrays;

public class project {
    public int monotoneIncreasingDigits(int n) {
        if(n<10){
            return n;
        }
        char[] chs=String.valueOf(n).toCharArray();
        int len=chs.length;
        int index=0;
        while (index<len-1){
            if(chs[index]>chs[index+1]){
                break;
            }
            index++;
        }
        if(index==len-1){
            return n;
        }
        boolean flag=false;
        for(int i=0;i<len;i++){
            if(chs[i]==chs[index]&&!flag){
                chs[i]--;
                flag=true;
            }else if(flag){
                chs[i]='9';
            }
        }
        String str="";
        int i=0;
        for(i=0;i<len;i++){
            if(chs[i]!='0'){
                break;
            }
        }
        for(;i<len;i++){
            str+=chs[i];
        }
        return Integer.parseInt(str);
    }




















    public int compress(char[] chars) {
        int len=chars.length;
        int left=0;
        int index=0;
        for(int i=0;i<len;i++){
            if(i==len-1||chars[i]!=chars[i+1]){
                chars[index]=chars[i];
                index++;
                int sum=i-left+1;
                if (sum>1){
                    String str=String.valueOf(sum);
                    for(int j=0;j<str.length();j++){
                        chars[index]=str.charAt(j);
                        index++;
                    }
                }
                left=i+1;
            }
        }
        return index;
    }















    public boolean oneEditAway(String first, String second) {
        int len1=first.length();
        int len2=second.length();
        if(Math.abs(len1-len2)>1){
            return false;
        }
        int index1=0;
        int index2=0;
        int count=0;
        while (count<2&&index1<len1&&index2<len2){
            if(first.charAt(index1)==second.charAt(index2)){
                index1++;
                index2++;
            }else if(index1<len1-1&&first.charAt(index1+1)==second.charAt(index2)){
                index1++;
                count++;
            }else if(index2<len2-1&&first.charAt(index1)==second.charAt(index2+1)){
                index2++;
                count++;
            }else{
                index1++;
                index2++;
                count++;
            }
        }
        count+=len1-index1+len2-index2;
        return count<2;
    }
}
